package com.yaoweigroup.community.adapter;

import java.util.List;

import com.yaoweigroup.community.R;
import com.yaoweigroup.community.enity.DiscountOrder;
import com.yaoweigroup.community.enity.MenuInfo;
import com.yaoweigroup.community.enity.OrderInfo;
import com.yaoweigroup.community.enity.SportOrder;
import com.yaoweigroup.community.interfaze.Callback;
import com.yaoweigroup.community.util.Tools;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MyWtAdapter extends BaseAdapter {

	private Context context;
	private List<SportOrder> list;
	private LayoutInflater mInflater;
	public Callback callback;

	// ，，，，，，

	public MyWtAdapter(Context context, List<SportOrder> list) {
		mInflater = LayoutInflater.from(context);
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.adapter_my_wt_list_item,
					null);
			holder.time_tv = (TextView) convertView.findViewById(R.id.time_tv);
			holder.start_tv = (TextView) convertView
					.findViewById(R.id.start_tv);
			holder.end_tv = (TextView) convertView.findViewById(R.id.end_tv);
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.price_tv = (TextView) convertView
					.findViewById(R.id.price_tv);
			holder.cancel_bt = (Button) convertView
					.findViewById(R.id.cancel_bt);
			convertView.setTag(holder);

		} else {
			holder = (Holder) convertView.getTag();
		}

		final SportOrder order = list.get(position);
		holder.time_tv.setText("订单时间:" + order.getOrderDate());
		holder.start_tv.setText("开始时间:" + order.getBeginTime());
		holder.end_tv.setText("结束时间:" + order.getEndTime());
		holder.name_tv.setText("场馆名字:" + order.getSiteName());
		holder.price_tv.setText("价格:¥" + order.getCost());
		holder.cancel_bt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (callback != null) {
					callback.callback(order.getGuid(), 0, 0);
				}
			}
		});
		return convertView;
	}

	public final class Holder {

		TextView time_tv;
		TextView start_tv;
		TextView end_tv;
		TextView name_tv;
		TextView price_tv;
		Button cancel_bt;
	}

	public void setCallback(Callback callback) {
		this.callback = callback;

	}

	public void setDataChange(List<SportOrder> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
